/**
 * 组合审核
 */
import Vue from 'vue'
const SUCCESS = 1000000
const API_ROOT = server.root + '/newmanage'

const getCheckGroupListResource = Vue.resource(API_ROOT + '/rank/home/list')
const getCheckGroupUpdateResource = Vue.resource(API_ROOT + '/rank/home/update')
const setTurnTimeResource = Vue.resource(API_ROOT + '/rank/home/vip/autoIntro/loopTime')
const getSetTurnTimeResource = Vue.resource(API_ROOT + '/rank/home/vip/autoIntro/loopTime/get')
const getHeroTurnStatusResource = Vue.resource(API_ROOT + '/rank/home/ vip/autoIntro')
const getAutoNewTimeResource = Vue.resource(API_ROOT + '/rank/home/audit')

/**
 * 审核组合列表
 */
export const getCheckGroupList = ({dispatch}, {type = 1}) => {
  return getCheckGroupListResource.get({
    type: type
  })
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return Promise.resolve(res.data.data)
      }
      return Promise.reject(res.data)
    })
}
/**
 * 审核组合列表更新
 */
export const getCheckGroupUpdate = ({dispatch}, params) => {
  return getCheckGroupUpdateResource.get(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return Promise.resolve(res.data.data)
      }
      return Promise.reject(res.data)
    })
}
/*
 * 审核组合设置轮播时间
 */
export const getSetTurnTime = () => {
  return getSetTurnTimeResource.get()
    .then((res) => {
      if (res.data.success === true) {
        return Promise.resolve(res.data)
      }
      return Promise.reject(res.data)
    })
}
export const setTurnTime = ({dispatch}, params) => {
  return setTurnTimeResource.get(params)
    .then((res) => {
      if (res.data.success === true) {
        return Promise.resolve(res.data)
      }
      return Promise.reject(res.data)
    })
}
/*
 *设置英雄榜轮播状态
 */
export const getHeroTurnStatus = () => {
  return getHeroTurnStatusResource.get({})
    .then((res) => {
      if (res.data.auto) {
        return Promise.resolve(res.data)
      }
      return Promise.reject(res.data)
    })
}
/*
 *点击审核获取最新时间
 */
export const getAutoNewTime = ({dispatch}, params) => {
  return getAutoNewTimeResource.get(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return Promise.resolve(res.data)
      }
      return Promise.reject(res.data)
    })
}

const recommendFollowListResource = Vue.resource(API_ROOT + '/common/app/attention/list')
export const getRecommendFollowList = ({dispatch}, params) => {
  return recommendFollowListResource.get(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        dispatch('PORTFOLIO_LIST_NEED_FRESH', 0)
        return Promise.resolve(res.data.data)
      }
      return Promise.reject(res.data)
    })
}

const saveRecommendFollowResource = Vue.resource(API_ROOT + '/common/app/attention/save')
export const saveRecommendFollow = ({dispatch}, params) => {
  return saveRecommendFollowResource.save(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return dispatch('PORTFOLIO_LIST_NEED_FRESH', 1)
      }
      return Promise.reject(res.data)
    })
}

const deleteRecommendFollowResource = Vue.resource(API_ROOT + '/common/app/attention/delete')
export const deleteRecommendFollow = ({dispatch}, params) => {
  return deleteRecommendFollowResource.save(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return dispatch('PORTFOLIO_LIST_NEED_FRESH', 1)
      }
      return Promise.reject(res.data)
    })
}

const swapRecommendFollowResource = Vue.resource(API_ROOT + '/common/app/attention/move')
export const swapRecommendFollow = ({dispatch}, params) => {
  return swapRecommendFollowResource.save(params)
    .then((res) => {
      if (+res.data.code === SUCCESS) {
        return dispatch('PORTFOLIO_LIST_NEED_FRESH', 1)
      }
      return Promise.reject(res.data)
    })
}
